﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 自旋锁
{
    public class QueueLock<T>
    {
        Queue<T> msgQueue = new Queue<T>(65536);
        object objLock = new object();

        public int GetQueueCount()
        {
            return msgQueue.Count;
        }

        public void InQueue(T t)
        {
            lock (objLock)
            {
                msgQueue.Enqueue(t);
            }
        }

        public T OutQueue()
        {
            lock (objLock)
            {
                return msgQueue.Dequeue();
            }
        }
    }
}
